﻿using System;
using System.Drawing;
using System.Windows.Forms;
using Quakk.Twitter;

namespace Quakk.Forms
{
    public partial class TweetForm : Form
    {
        private readonly TwitterApi twitterApi;

        public string TweetText
        {
            get { return textBox.Text; }
            set { textBox.Text = value; }
        }

        public TweetForm(TwitterApi twitterApi)
        {
            this.twitterApi = twitterApi;

            InitializeComponent();
        }

        private void menuItemCancel_Click(object sender, EventArgs e)
        {
            Close();
        }

        private void TweetForm_Load(object sender, EventArgs e)
        {
            BackColor = Display.BackgroundColour;
            textBox.Select(textBox.Text.Length, 0);
        }

        private void menuItemSend_Click(object sender, EventArgs e)
        {
            Cursor.Current = Cursors.WaitCursor;
            try
            {
                twitterApi.SendTweet(textBox.Text);
                Close();
            }
            catch(TwitterResponseException ex)
            {
                MessageBox.Show(ex.Message);
            }
            finally
            {
                Cursor.Current = Cursors.Default;
            }
        }

        private void TweetForm_Resize(object sender, EventArgs e)
        {
            if(Width < Height)
            {
                textBox.Size = new Size(214, 139);
                textBox.Location = new Point(13, 67);
                label.Size = new Size(214, 19);
                label.Location = new Point(13, 45);
            }
            else
            {
                textBox.Size = new Size(294, 100);
                textBox.Location = new Point(13, 37);
                label.Size = new Size(294, 19);
                label.Location = new Point(13, 15);
            }
        }
    }
}